package com.mazaiting.classfile.attr.info;

import com.mazaiting.classfile.ClassReader;
import com.mazaiting.classfile.attr.entity.ParametersEntity;
import com.mazaiting.classfile.constant.ConstantPool;

import java.util.Arrays;

/**
 * 方法参数实体
 *
 * @author mazaiting
 * @since 2021/8/13
 */
public class MethodParametersAttribute extends AttributeInfo {
    /**
     * 参数个数 u1
     */
    private short parametersCount;
    /**
     * 参数实体
     */
    private ParametersEntity[] parametersEntities;

    public MethodParametersAttribute(ConstantPool pool, int index, int length) {
        super(pool, index, length);
    }

    @Override
    public void readInfo(ClassReader reader) {
        this.parametersCount = reader.readU1ToUnsignedByte();
        this.parametersEntities = new ParametersEntity[parametersCount];
        for (int i = 0; i < parametersCount; i++) {
            this.parametersEntities[i] = new ParametersEntity(
                    reader.readU2ToUnsignedShort(),
                    reader.readU2ToUnsignedShort()
            );
        }
    }

    @Override
    public String toString() {
        return "MethodParametersAttribute{" +
                "nameIndex=" + nameIndex +
                ", length=" + length +
                ", parametersCount=" + parametersCount +
                ", parametersEntities=" + Arrays.toString(parametersEntities) +
                '}';
    }
}


















